<?php
class ModelSurveySurvey extends Model {
	public function getSurvey($survey_id) {
		
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "survey i LEFT JOIN " . DB_PREFIX . "survey_description id ON (i.survey_id = id.survey_id) LEFT JOIN " . DB_PREFIX . "survey_to_store i2s ON (i.survey_id = i2s.survey_id) WHERE i.survey_id = '" . (int)$survey_id . "' AND id.language_id = '" . (int)$this->config->get('config_language_id') . "' AND i2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND i.status = '1'");
	
		return $query->row;
	}
	
	public function getSurveys() {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "survey i LEFT JOIN " . DB_PREFIX . "survey_description id ON (i.survey_id = id.survey_id) LEFT JOIN " . DB_PREFIX . "survey_to_store i2s ON (i.survey_id = i2s.survey_id) WHERE id.language_id = '" . (int)$this->config->get('config_language_id') . "' AND i2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND i.status = '1' AND i.sort_order <> '-1' ORDER BY i.sort_order, LCASE(id.title) ASC");
		
		return $query->rows;
	}
	
	public function getSurveyLayoutId($survey_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "survey_to_layout WHERE survey_id = '" . (int)$survey_id . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");
		 
		if ($query->num_rows) {
			return $query->row['layout_id'];
		} else {
			return $this->config->get('config_layout_survey');
		}
	}
	
	public function getSurveysDone($email) {
		$data = array();
		
		$query = $this->db->query("SELECT distinct survey_id FROM `mo_answer` WHERE email = '" . $this->db->escape($email) . "'");
		
		foreach($query->rows as $each_row) {
			$data[] = $each_row['survey_id'];
		}
		
		return $data;
	}
	
	public function getPositions() {
		/*
		16 = Reasoning
		13 = Image Test
		12 = MBTI
		11 = Dr. Phill
		15 = Mental Agility
		14 = Maslow
		*/
		
		$data = array();
		
		$data[1] = array('position_id' => 1, 'name' => 'AM', 'tests' => '16,11,14');		
		$data[2] = array('position_id' => 2, 'name' => 'Business Manager', 'tests' => '12,15,14,16,13');
		$data[14] = array('position_id' => 14, 'name' => 'Content Writer', 'tests' => '12,13,14,16');
		$data[3] = array('position_id' => 3, 'name' => 'Link Builders', 'tests' => '13');
		$data[4] = array('position_id' => 4, 'name' => 'Marketing Executive / Corp Executive', 'tests' => '12,16,14,15');
		$data[5] = array('position_id' => 5, 'name' => 'Marketing Manager / Corp Manager', 'tests' => '12,16,14,15');
		$data[6] = array('position_id' => 6, 'name' => 'Operation Manager', 'tests' => '12,15,14,16,13');
		$data[7] = array('position_id' => 7, 'name' => 'PHP/ Designer', 'tests' => '13,11,16');
		$data[8] = array('position_id' => 8, 'name' => 'PO', 'tests' => '13');
		$data[9] = array('position_id' => 9, 'name' => 'SAM', 'tests' => '12,16,14');
		$data[10] = array('position_id' => 10, 'name' => 'SEO Executive', 'tests' => '13');
		$data[11] = array('position_id' => 11, 'name' => 'Senior PHP and Designer', 'tests' => '13,11,16');
		$data[12] = array('position_id' => 12, 'name' => 'Support Executive', 'tests' => '13');
		$data[13] = array('position_id' => 13, 'name' => 'Technical Executive', 'tests' => '13');					
		
		return $data;
	}
}
?>